﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;

namespace ClassLibrary.DAO
{
   public class TblTypeDAO
    {
       private DBService _db = null;

       public TblTypeDAO(String ConnectionString)
       {
           _db = new DBService(ConnectionString);
       }

       public DataTable GetAll()
       {
           DataTable dt = null;
           try
           {         
               dt = _db.ExeSP_DataTable("Select * from TblType", false, CommandType.Text);
           }
           catch (Exception ex)
           {
               throw ex;
           }
           return dt;
       }

       public DataTable GetState()
       {
           DataTable dt = null;
           try
           {
               dt = _db.ExeSP_DataTable("Select * from AUState", false, CommandType.Text);
           }
           catch (Exception ex)
           {
               throw ex;
           }
           return dt;
       }

       public DataTable GetSuburb(string state, string postcode)
       {
           DataTable dt = null;
           try
           {
               dt = _db.ExeSP_DataTable("select * from " +
                    "(select b.*  from  AUSuburb b, AUState where AUState.state=b.state and b.state= @state)A  where postcode= @postcode",
                    new string[] { "@state", "@postcode" },
                    new object[] { state, postcode },
                    CommandType.Text);

           }
           catch (Exception ex)
           {
               throw ex;
           }
           return dt;
       }

    }
}
